package com.feicheng.controller.shop.admin.system;


import com.feicheng.common.constant.Constant;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.Permission;
import com.feicheng.persistence.entity.StorePermission;
import com.feicheng.service.IFSystemService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2021-12-02
 */
@RestController("/shop/admin/permission")
@RequestMapping("/shop/admin/permission")
public class StorePermissionController {

    /* 通过依赖查找实现多实现BEAN的调用 */
    @Resource(name="system-service")
    Map<String, IFSystemService> systemServiceBean;

    @DeleteMapping("/info")
    public ResultInfo deletePermissionInfo(Integer permissionId) {
        return systemServiceBean.get(Constant.MODEL_NAME.SHOP).deletePermission(permissionId);
    }

    @PostMapping("/info")
    public ResultInfo addPermissionInfo(StorePermission permission) {
        return systemServiceBean.get(Constant.MODEL_NAME.SHOP).addPermission(permission);
    }

    @PutMapping("/info")
    public ResultInfo updatePermissionInfo(StorePermission permission) {
        return systemServiceBean.get(Constant.MODEL_NAME.SHOP).updatePermission(permission);
    }

    @GetMapping("/info")
    public ResultInfo getPermissionInfo(Integer permissionId) {
        return systemServiceBean.get(Constant.MODEL_NAME.SHOP).getPermission(permissionId);
    }

    @GetMapping("/list")
    public ResultInfo getPermissionList(
            String name,
            String path,
            Boolean statu,
            Integer pId,
            @RequestParam(defaultValue="1") Integer currentPage,
            @RequestParam(defaultValue="10")Integer pageSize
    ) {
        return systemServiceBean.get(Constant.MODEL_NAME.SHOP).getPermissions(name, path, statu, pId, currentPage, pageSize);
    }

    @GetMapping("/all")
    public ResultInfo allPermissions() {
        return systemServiceBean.get(Constant.MODEL_NAME.SHOP).allPermissions(true, null);
    }
}
